<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>告警分类</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0"> 
	<meta http-equiv="X-UA-Compatible" content="IE=edge" />
	<jsp:include page="../resource.jsp"></jsp:include>
	<style type="text/css">
	    #authority table, caption, tbody, tfoot, thead, tr, th, td{
	        vertical-align: middle;
	    }
	</style>
	<script type="text/javascript">
	$(document).ready(function() {
		var h = '85%';
 		if($.browser.msie && ($.browser.version == 8.0 || $.browser.version == 9.0)){
 	    	 h = $(self.parent.parent.frames['mainFrame']).height()-87; 
 	    }
        $("#alarmClass").omGrid({
        	dataSource : 'alarmClass!findAll.do',
            height : h,
            limit : 20,
            showIndex : true,
            colModel : [ 
                         {header : '名称', name : 'name', width : 150, align : 'left'},
                         {header : '告警等级', name : 'level', width : 90, align : 'center'},
                         {header : '是否有效', name : 'enable', width : 90, align : 'center',renderer:function(value){
                             return value == 0 ?'无效':'有效';
                         }},
                         {header : '告警信息', name : 'format', width : 250, align : 'left'}, 
                         {header : '告警类型', name : 'type', width : 90, align : 'center',renderer:function(value){
                             if(value == '1') {
                            	 return '软件告警';
                             }else if(value == '2') {
                            	 return '硬件告警';
                             }else{
                            	 return '通信告警';
                             }
                         }} ]
        });
        
        $("#alarmEditor").omDialog({
        	autoOpen: false,
  		    height: 300,
  		    width : 480,
  		    buttons: [{
                text : "确定", 
                click : function () {
                  $("#alarmForm").submit();
                }
             }, {
                text : "取消", 
                click : function () {
                  $("#alarmEditor" ).omDialog("close");
              }
          }]
        });
        
        
        $("#alarmAdd").click(function(){
        	$("#alarmForm").resetForm();
        	$("#alarmClassId").val('');
        	$("#alarmEditor").omDialog("open");
        });
        
        $("#alarmDelete").click(function(){
        	var selects = $("#alarmClass").omGrid("getSelections",true);
        	if(selects.length <= 0){
        		$.omMessageBox.alert({content:'请您选择删除记录'});
        		return;
        	}
        	 $.omMessageBox.confirm({
                 title:'确认删除',
                 content:'您确定删除该数据？',
                 onClose:function(result){
                	 if(result){
                		 $.ajax({
                			 url : 'alarmClass!delete.do',
                			 data : {deleteId:selects[0].id},
                			 success : function(data){
                				 if(data == '1'){
                					 $.omMessageTip.show({timeout : 2000,content : '删除成功！'});
                					 $("#alarmClass").omGrid("reload");
                				 }else{
                					 $.omMessageTip.show({timeout : 2000,content : '删除失败！'});
                				 }
                			 }
                		 });
                	 }
                 }
             });

        	
        });
        
        $("#alarmModify").click(function(){
        	var selects = $("#alarmClass").omGrid("getSelections",true);
        	if(selects.length <= 0){
        		$.omMessageBox.alert({content:'请您选择修改记录'});
        		return;
        	}
        	$("#alarmForm").resetForm();
        	$("#alarmClassId").val(selects[0].id);
        	$("#alarmClassName").val(selects[0].name);
        	$("#alarmClassLevel").val(selects[0].level);
        	$("#alarmClassEnable").val(selects[0].enable);
        	$("#alarmClassFormat").val(selects[0].format);
        	$("#alarmClassType").val(selects[0].type);
        	$("#alarmEditor").omDialog("open");
        });
        
        var alarmOptions  = {
      		  url : 'alarmClass!save.do',
                success : function(data){
                   	if(data != '0'){  
                       	$.omMessageTip.show({timeout : 2000,content : '保存成功！'});
                       	$("#alarmEditor").omDialog('close');
                       	$("#alarmClass").omGrid("reload");
                   	}else{
                   		$.omMessageTip.show({timeout : 2000,content : '保存失败！',type : 'error'});
                   	}
                }
      	  };
      	  $("#alarmForm").submit(function() {
                $(this).omAjaxSubmit(alarmOptions);
                return false;//返回false,阻止浏览器默认行为
          });
    });
	</script>  
  </head>
  
  <body>
    <div class="toolbar mar">
		         <a href="#" class="rbutton" id="alarmAdd"><span><img src="../images/add.gif" width="14" height="14" /><ins>添加</ins></span></a>
		         <a  class="line"></A>
		         <a href="#" class="rbutton" id="alarmModify"><span><img src="../images/add.gif" width="14" height="14" /><ins>修改</ins></span></a>
		         <a  class="line"></A>
		         <a href="#" class="rbutton" id="alarmDelete"><span><img src="../images/del.gif" width="14" height="14" /><ins>删除</ins></span></a>
	</div>
    <table id="alarmClass"></table>
    
    <div id="alarmEditor" title="编辑分类" style="display: none;">
     <form id="alarmForm" method="post">
          <table width="100%" border="0" class="grid_layout" cellspacing="0">
             <tr>
               <td width="10%" align="right">名称：</td>
               <td width="28%" colspan="3" align="left">
                 <input type="hidden" id="alarmClassId" name="alarmClass.id">
                 <input type="text" name="alarmClass.name" id="alarmClassName" class="input_text"/>
               </td>
             </tr>
             <tr>
               <td width="10%" align="right">告警等级：</td>
               <td width="28%" colspan="3" align="left">
                 <select name="alarmClass.level" id="alarmClassLevel">
                 	<option value="1">1</option>
                 	<option value="2">2</option>
                 	<option value="3">3</option>
                 	<option value="4">4</option>
                 	<option value="5">5</option>
                 </select>
               </td>
             </tr>
             <tr>
               <td width="10%" align="right">是否有效：</td>
               <td width="10%" colspan="3" align="left">
                  <select name="alarmClass.enable" id="alarmClassEnable" >
	                  <option value="1">有效</option>
	                  <option value="0">无效</option>
                  </select>
               </td>
             </tr>
             <tr>
               <td width="10%" align="right">告警信息：</td>
               <td width="28%" colspan="3" align="left">
                  <input type="text" id="alarmClassFormat" name="alarmClass.format" class="input_text">
               </td>
             </tr>
             <tr>
               <td width="10%" align="right">告警类型：</td>
               <td width="28%" colspan="3" align="left">
                  <select name="alarmClass.type" id="alarmClassType" >
                  	<option value="1">软件告警</option>
                  	<option value="2">硬件告警</option>
                  	<option value="3">通信告警</option>
                  </select>
               </td>
             </tr>
           </table>
         </form>
   </div>
  </body>
</html>
